const pool = require("../../config/db");
module.exports.install = function (express) {
  const User = express.Router();
  User.get("/", function (req, res) {
    const userInfo = req.headers.userInfo;
    res.json({
      userInfo: userInfo,
    });
  });
  User.get("/getList", function (req, res) {
    let page = req.query.page || 1;
    let size = req.query.size || 5;

    pool.execute(
      "SELECT * FROM `user` LIMIT  ? ,  ?",
      [(page - 1) * size, size],
      function (err, rows1) {
        pool.execute(
          "SELECT user_id FROM `user`",
          [(page - 1) * size, size],
          function (err, rows) {
            res.json({
              code: 0,
              message: "查询成功",
              data: rows1,
              total: rows.length,
              size: size,
              page: page,
            });
          }
        );
      }
    );
  });
  return User;
};
